<?php include template('common/head') ?>
<div class="mdui-container">
    <div class="mdui-row">
        <div class="mdui-col-md-4 mdui-col-offset-md-4">
			<?php if($id){ ?>
			<div class="mdui-typo-subheading mdui-m-b-1 mdui-text-truncate">
				<?php if((isset($dir['_parentId']) and $dir['_parentId'] != NULL) or $dir['ccpParentFileId'] != 'root'){ ?>
				<a href="<?=$_CFG['url']?>/<?=$dir['_parentId'] ?: $dir['parentId']?>" class="mdui-ripple"><i class="mdui-icon material-icons">arrow_back</i></a>
				<?php } ?>
				<i class="mdui-icon material-icons mdui-m-r-1">folder</i>
				<?php
					$type = $dir['collectionType'] ?: $dir['ccpParentFileId'];
					if($type == 'root'){
						echo '根目录';
					}else{
						echo $dir['title'] ?: $dir['name'];
					}
				?>
				</div>
			<div class="mdui-divider mdui-m-b-2"></div>
			<div class="mdui-typo-body-1 mdui-m-b-1 mdui-text-center">此目录设置了访问权限,请输入密码！</div>
			<?php }else{ ?>
				<div class="mdui-typo-body-1 mdui-m-b-1 mdui-text-center">网站设置了访问权限,请输入密码！</div>
			<?php } ?>
			<div class="mdui-textfield mdui-textfield-floating-label">
				<label class="mdui-textfield-label">访问密码</label>
				<input name="password" class="mdui-textfield-input" type="password"/>
			</div>
			<button id="submit" class="mdui-btn mdui-btn-raised mdui-btn-block mdui-m-t-1" style="background-color:#1b9aee;color:#fff;">确认</button>
        </div>
    </div>
</div>
<?php include template('common/foot') ?>
<script>
$(function(){
	$('#submit').click(function(){
		var password = $('input[name=password]').val();

		if(!password)return mdui.snackbar({message: '密码不能为空',position: 'right-top'});

		$('#loading').fadeToggle();
		$.ajax({
			type:"POST",
			url:window.location.pathname,
			data:{
				password:password,
				<?php
				if($id)echo 'id:'."'$id'";
				?>

			},
			dataType:'json',
			success:function(data){
				$('#loading').fadeToggle();
				if(data.code == 200){
					mdui.snackbar({
						message: data.msg,
						position: 'right-top',
						timeout: 3000,
						onClose: function(){
							window.location.reload();
						}
					});
				}else{
					mdui.snackbar({
						message: data.msg,
						position: 'right-top'
					});
				}
			},
			error:function(){
				$('#loading').fadeToggle();
				mdui.snackbar({
					message: '系统繁忙',
					position: 'right-top'
				});
			}
		})
	});
});
</script>